//
//  ViewController.m
//  BaichuanDemo
//
//  Created by a on 2019/3/19.
//  Copyright © 2019 MGXD. All rights reserved.
//

#import "ViewController.h"
#import <AlibcTradeSDK/AlibcTradeSDK.h>
#import "MainViewController.h"
#import "WKWebViewController.h"

@interface ViewController ()

@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.hidden = YES;
}
- (IBAction)goWebView:(id)sender {
//    https://s.click.taobao.com/iHin4Ew
    WKWebViewController *main = [[WKWebViewController alloc] init];
    [self.navigationController pushViewController:main animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
//    self.navigationController.navigationBar.hidden = YES;
    
}
- (IBAction)go:(id)sender {
    
    //打开商品详情页
    id<AlibcTradePage> page = [AlibcTradePageFactory itemDetailPage: @"582761060189"];
    
    //根据链接打开页面
//    id<AlibcTradePage> page = [AlibcTradePageFactory page: @"http://h5.m.taobao.com/cm/snap/index.html?id=527140984722"];
    
    //打开店铺
//    id<AlibcTradePage> page = [AlibcTradePageFactory shopPage: @”12333333”];
    
    
    //淘客信息
    AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
    taoKeParams.pid=@"mm_131663667_60700425_11149650015"; //
    //打开方式
    AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
    showParam.openType = AlibcOpenTypeAuto;//AlibcOpenTypeH5 强制h5展示
    
    [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
        NSLog(@"%@",result);
    } tradeProcessFailedCallback:^(NSError * _Nullable error) {
        NSLog(@"%@",error);
    }];
    
}


- (IBAction)webGo:(id)sender {
    BOOL can = [AlibcLinkPartnerBridge canOpenApp:@"tbopen"];
    if (can) {
        
    } else {
        
    }
    
    
//    id<AlibcTradePage> page = [AlibcTradePageFactory itemDetailPage: @"582761060189"];
    id<AlibcTradePage> page = [AlibcTradePageFactory myCartsPage];//创建我的购物车页面
    
    //淘客信息
    AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
    taoKeParams.pid= @"mm_131663667_60700425_11149650015";
    //打开方式
    AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
    showParam.openType = AlibcOpenTypeH5;
    
    
    // YourWebViewController类中,webview的delegate设置不能放在viewdidload里面,必须在init的时候,否则函数调用的时候还是nil
    MainViewController * myView = [[MainViewController alloc] init];
    
    
    NSInteger ret = [[AlibcTradeSDK sharedInstance].tradeService show: myView webView: myView.web page:page showParams:showParam taoKeParams: taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
        
    } tradeProcessFailedCallback:^(NSError * _Nullable error) {
        
    } ];
    //返回1,说明h5打开,否则不应该展示页面
    if (ret == 1) {
        [self.navigationController pushViewController:myView animated:YES];
    }
}

@end
